package io.netty.shenh.example.inboundoutbound;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * msg传播到MessageToByteEncoder的子类时, MessageToByteEncoder会判断数据是否匹配泛型,
 * 如果不匹配, 不会调用子类encode()方法, 而是直接传播下去
 */
public class MyLong2ByteEncoder extends MessageToByteEncoder<Long> {
    @Override
    protected void encode(ChannelHandlerContext ctx, Long msg, ByteBuf out) throws Exception {
//        System.out.println("MyLong2ByteEncoder-encode 被调用");
        System.out.println("msg=" + msg);
        out.writeLong(msg);
    }


}
